package com.ycc.biz.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * 分页响应对象
 */
@Data
@ApiModel("分页响应")
public class PageResult<T> {
    
    @ApiModelProperty("数据列表")
    private List<T> records;
    
    @ApiModelProperty("总记录数")
    private long total;
    
    @ApiModelProperty("每页大小")
    private long size;
    
    @ApiModelProperty("当前页码")
    private long current;
    
    @ApiModelProperty("总页数")
    private long pages;
    
    /**
     * 从 MyBatis-Plus 的 Page 对象构建分页响应
     */
    public static <T> PageResult<T> build(Page<T> page) {
        PageResult<T> result = new PageResult<>();
        result.setRecords(page.getRecords());
        result.setTotal(page.getTotal());
        result.setSize(page.getSize());
        result.setCurrent(page.getCurrent());
        result.setPages(page.getPages());
        return result;
    }
} 